export default {
  namespaced: true,
  state: () => ({
    address: JSON.parse(uni.getStorageSync('address') || '{}'),
    token: uni.getStorageSync('token') || '',
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
    redirectinfo: null,
  }),
  mutations: {
    //重定向
    updateRedirectinfo (state, info) {
      state.redirectinfo = info
    },
    updateAddress (state, address) {
      state.address = address
      this.commit('user/saveData')
    },
    //更新用户基本信息
    updateUserInfo (state, userinfo) {
      state.userinfo = userinfo
      this.commit('user/saveUserInfo')
    },
    //更新token
    updateToken (state, token) {
      state.token = token
      this.commit('user/saveToken')
    },
    // 将数据存储到本地
    saveData(state) {
      uni.setStorageSync('address', JSON.stringify(state.address))
    },
    saveUserInfo (state) {
      uni.setStorageSync('userinfo', JSON.stringify(state.userinfo))
    },
    saveToken (state) {
      uni.setStorageSync('token', state.token)
    }
    
  },
  actions: {},
  // 计算属性
  getters: {
    addstr (state) {
      if(!state.address.provinceName) return ''
      // 拼接 省，市，区，详细地址 的字符串并返回给用户
          return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
  }
}